/*
 * $Id: DisplayUtil.java 71 2009-04-21 13:37:37Z meyer@alphatec.de $
 * 
 *
 * Copyright 2009 DeltaDesk
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package deltadesk.gui.deltagui.display;

import java.awt.AWTException;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.Point;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.image.BufferedImage;


/**
 * DisplayUtil
 * 
 * @author Andreas Meyer
 * @version $Revision: 71 $
 */
public class DisplayUtil {
	
	private static final Cursor blankCursor;
	
	/** The mouse controller robot. */
	private static Robot robot;


	
	static {

		// create blank cursor
		final BufferedImage img = new BufferedImage(3, 3,
				BufferedImage.TYPE_INT_ARGB);
		blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(img,
				new Point(0, 0), "blank");
		
		try {
			robot = new Robot();
		} catch (AWTException e) { /* Ignore */ }
	}

	public static void hideMouseCursor(final Component component) {
		
		component.setCursor(blankCursor);
		
		// create mouse controller
		if(robot != null) {

			component.addMouseMotionListener(new MouseMotionAdapter() {

				public void mouseMoved(final MouseEvent me) {

					// Keep mouse pointer inside the content pane to prevent
					// showing the cursor outside the edges
					robot.mouseMove(10, 10);
				}
			});
		} // end if
	}
}
